package com.hualan.sfzy.controller.counselor;

import com.hualan.sfzy.entity.counselor.Talent;
import com.hualan.sfzy.service.counselor.TalentService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class TalentController {
    @Autowired
    private TalentService talentService;

    @PostMapping("/talent")
    public Result add(@RequestBody Talent talent){
        int num = talentService.add(talent);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/talent/{id}")
    public Result remove(@PathVariable Integer id){
        int num = talentService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/talent")
    public Result removeBatch(Integer[] ids){
        int num = talentService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/talent")
    public Result edit(@RequestBody Talent talent){
        int num = talentService.edit(talent);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/talent")
    public Result find(){
        List<Talent> list = talentService.find();
        return Result.success(list);
    }

    @GetMapping("/talent/{id}")
    public Result findById(@PathVariable Integer id){
        Talent talent = talentService.findById(id);
        return Result.success(talent);
    }

    @GetMapping("/talent/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     Talent talent){
        Map<String, Object> map = talentService.findByPage(pageNum, pageSize, talent);
        return Result.success(map);
    }
}
